(function(exports) {
	var gc = gameConfig,
		h = gc.height,
		sp = gc.speed;

	exports.Bird = function(pos, keyMap) {
		this.pos = pos || new Vec2();
		this.keyMap = keyMap || {};
		this.size = 10;
		this.spY = 0;
		this.alive = true;
	}

	exports.Bird.prototype = {
		constructor: Bird,
		flap: function() {
			this.spY = -gc.flapPower;
		},
		update: function(keyPress) {
			this.spY = this.spY + gc.secSpan * gc.g;
			this.pos.y += this.spY;
			if (this.alive) {
				if (keyPress[this.keyMap['flap']]) {
					this.flap();
					keyPress[this.keyMap['flap']] = false;
				}
			} else {
				this.pos.x -= gc.secSpan * sp;
			}
		},
		hitTest: function(pipe) {
			if (this.alive) {
				if (this.pos.y <= 0) return true;
				if (this.pos.y + this.size >= h) return true;
			}
			if (pipe) {
				return this.pos.x < pipe.pos.x+gc.pipeWidth &&
					this.pos.x + this.size > pipe.pos.x &&
					this.pos.y < pipe.pos.y+pipe.height &&
					this.pos.y + this.size > pipe.pos.y;
			}
			return false;
		},
		draw: function(ctx) {
			//ctx.beginPath();
			//ctx.rect(this.pos.x,this.pos.y,this.size,this.size);
			//ctx.closePath();
			ctx.strokeRect(this.pos.x, this.pos.y, this.size, this.size);
			//ctx.fillRect(this.pos.x,this.pos.y,this.size,this.size);
		}
	}
})(window);